#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const int N = 100005;
const int L = 1000005;
ll n, m, l, k, id[N], t[L];
vector<pii> ans;
struct Car
{
    ll d, v, a;
}a[N];
ll calc(int x, int to)
{
    return a[x].v * a[x].v + 2 * a[x].a * (to - a[x].d);
}
void init()
{
    memset(t, 0, sizeof t);
    ans.clear();
}
ll ans1, ans2;
bool bo[205];
void dfs(ll step, ll tot)
{
    if (step == m + 1)
    {
        ll ret = 0;
        for (int i = 1; i <= n; ++i)
        {
            for (int j = 1; j <= m; ++j)
            {
                if (!bo[j]) continue;
                if (id[j] > a[i].d && calc(i, id[j]) > k * k)
                {
                    ret++;
                    break;
                }
            }
        }
        if (ret == ans1) ans2 = min(ans2, tot);
        return;
    }
    dfs(step + 1, tot);
    bo[step] = 1;
    dfs(step + 1, tot + 1);
    bo[step] = 0;
}
void solve0()
{
    ans1 = 0, ans2 = 2e9;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            if (id[j] > a[i].d && calc(i, id[j]) > k * k)
            {
                ans1++;
                break;
            }
        }
    }
    dfs(1, 0);
    cout << ans1 << " " << m - ans2 << endl;
    return;
}
bool FLAG = 1;
void solve()
{
    init();
    cin >> n >> m >> l >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i].d >> a[i].v >> a[i].a;
    for (int i = 1; i <= m; ++i) cin >> id[i];
    l = min(l, id[m]);
    if (n <= 20)
    {
        memset(bo, 0, sizeof bo);
        solve0();
        return;
    }
    t[l + 1] = m + 1;
    ll tmp = m;
    for (int i = l; i >= 0; --i)
    {
        if (id[tmp] == i)
        {
            t[i] = tmp;
            tmp--;
        }
        else t[i] = t[i + 1];
        //cout << t[i] << " ";
    }
    //cout << endl;
    for (int i = 1; i <= n; ++i)
    {
        if (a[i].a != 0) FLAG = 0;
         if (a[i].a == 0)
         {
             if (a[i].v <= k || t[a[i].d] > m) continue;
             ans.push_back(make_pair(t[a[i].d], m));
         }
         else if (a[i].a > 0)
         {
             if (calc(i, l) <= k * k) continue;
             ll lft = t[a[i].d] - 1, rgt = m + 1, mid;
             while (lft + 1 < rgt)
             {
                 mid = lft + rgt >> 1;
                 if (calc(i, id[mid]) > k * k) rgt = mid;
                 else lft = mid;
             }
             if (rgt > m) continue;
             ans.push_back(make_pair(rgt, m));
         }
         else if (a[i].a < 0)
         {
             if (calc(i, t[a[i].d]) <= k * k) continue;
             ll lft = t[a[i].d] - 1, rgt = m + 1, mid;
             while (lft + 1 < rgt)
             {
                 mid = lft + rgt >> 1;
                 if (calc(i, id[mid]) > k * k) lft = mid;
                 else rgt = mid;
             }
             if (t[a[i].d] > lft) continue;
             ans.push_back(make_pair(t[a[i].d], lft));
        }
    }
    sort(ans.begin(), ans.end());
    if (FLAG)
    {
        cout << ans.size() << " " << 1 << endl;
        return;
    }
    ll minr = 2e9, cnt = 0;
    for (int i = 0; i < ans.size(); ++i)
    {
        //cout << ans[i].first << " " << ans[i].second << endl;
        if (minr >= ans[i].first) minr = min(minr, ans[i].second);
        else
        {
            cnt++;
            minr = 2e9;
        }
    }
    cout << ans.size() << " " << m - cnt << endl;
}
int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int T;
    cin >> T;
    while (T--) solve();
    return 0;
}
